package com.example.noteapp.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.noteapp.Entity.EntityNoteCard;
import com.example.noteapp.R;

import java.util.ArrayList;


public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder> {
    //构造Adapter的时候调用这个构造方法，要传入这俩个
    ArrayList<EntityNoteCard> list;
    Context context;

    public NoteAdapter(ArrayList<EntityNoteCard> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public NoteAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_note, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull NoteAdapter.ViewHolder holder, int position) {
        holder.username.setText(list.get(position).getUsername());
        holder.slogan.setText(list.get(position).getSlogan());
        holder.createTime.setText(list.get(position).getCreateTime());
        holder.title.setText(list.get(position).getTitle());
        holder.content.setText(list.get(position).getContent());
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                System.out.println("delete is running");
            }
        });


    }

    @Override
    public int getItemCount() {
        return list.size();
    }
//用来绑定视图的工具类 对于item_note 有8个参数
    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView uerAvatar;
        TextView username;
        TextView slogan;
        TextView createTime;
        ImageView cover;
        TextView title;
        TextView content;
        Button delete;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            uerAvatar=itemView.findViewById(R.id.user_avatar);
            username=itemView.findViewById(R.id.username);
            slogan=itemView.findViewById(R.id.slogan);
            createTime=itemView.findViewById(R.id.create_time);
            cover=itemView.findViewById(R.id.cover);
            title=itemView.findViewById(R.id.title);
            content=itemView.findViewById(R.id.content);
            delete = itemView.findViewById(R.id.delete);

        }
    }
}
